package windbell.domain.risk.impl;

import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Date;
import org.hibernate.Query;
import windbell.domain.risk.RiskCheckTarget;
import windbell.domain.risk.RiskReport;
import windbell.domain.risk.RiskReportCriteria;
import windbell.domain.risk.RiskReportStatus;

public class RiskReportCriteriaImpl extends HQLBasedPagedQueryCriteria<RiskReport> implements RiskReportCriteria {
  private RiskCheckTarget checkTarget;
  
  public RiskCheckTarget getCheckTarget() {
    return this.checkTarget;
  }
  
  public RiskReportCriteria setCheckTarget(final RiskCheckTarget checkTarget) {
    this.checkTarget = checkTarget;
    return this;			
    
  }
  
  private RiskReportStatus status;
  
  public RiskReportStatus getStatus() {
    return this.status;
  }
  
  public RiskReportCriteria setStatus(final RiskReportStatus status) {
    this.status = status;
    return this;			
    
  }
  
  private Date dateFrom;
  
  public Date getDateFrom() {
    return this.dateFrom;
  }
  
  public RiskReportCriteria setDateFrom(final Date dateFrom) {
    this.dateFrom = dateFrom;
    return this;			
    
  }
  
  private Date dateTo;
  
  public Date getDateTo() {
    return this.dateTo;
  }
  
  public RiskReportCriteria setDateTo(final Date dateTo) {
    this.dateTo = dateTo;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from windbell.domain.risk.impl.RiskReportImpl this ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCheckTarget()) ){
    	hql += " and ((this.riskCheckItem.riskCheck.checkTarget) = (:checkTarget))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus()) ){
    	hql += " and ((this.Status) = (:status))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateFrom()) ){
    	hql += " and ((this.foundDate) >= (:dateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateTo()) ){
    	hql += " and ((this.foundDate) <= (:dateTo))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.foundDate",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getCheckTarget())){
    	query.setParameter("checkTarget",getCheckTarget()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus())){
    	query.setParameter("status",getStatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateFrom())){
    	query.setParameter("dateFrom",getDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getDateTo())){
    	query.setParameter("dateTo",getDateTo()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return false;
  }
  
  public RiskReportCriteriaImpl() {
    initOrderBys();
  }
}
